# -*- coding: utf-8 -*-
import scrapy
from ..items import MovieItem


class MeijuSpider(scrapy.Spider):
    name = 'meiju'   # 爬虫名
    allowed_domains = ['meijutt.com']   # 爬虫基础域名
    start_urls = ['https://www.meijutt.com/new100.html']

    def parse(self, response):
        res = response.xpath('//ul[@class="top-list  fn-clear"]/li')
        for r in res:
            # 电影名
            movie_name = r.xpath('h5/a/text()').extract_first()
            # 电影类别
            movie_type = r.xpath('span[@class="mjjq"]/text()').extract_first()
            # 放映tv
            movie_tv = r.xpath('span[@class="mjtv"]/text()').extract_first()
            # 最后更新时间
            lasted_time = r.xpath('div[@class="lasted-time new100time fn-right"]//text()').extract_first()
            print(movie_name, movie_type, movie_tv, lasted_time)

            # 创建item对象
            item = MovieItem()
            item['movie_name'] = movie_name
            item['movie_type'] = movie_type
            item['movie_tv'] = movie_tv
            item['lasted_time'] = lasted_time

            yield item
